<?php

namespace App\Console\Commands;

use App\Common\Business\MrpChangeLog;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class MrpChangeTopLastWeek extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'MrpTop';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '记录上周积分增长前10的用户，每周一执行查询';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $beginLastweek = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
        $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
        $res = (new MrpChangeLog())->recordMrpChangeTopLastWeek();
        if ($res) {
            Log::channel('mrptop')->info(date('y:m:d', $beginLastweek).'-'.date('y:m:d', $endLastweek).'积分增长最多的10位用户数据：'.json_encode($res));
        } else {
            Log::channel('mrptop')->info('上周未发现用户的积分增长');
        }
    }
}
